/**
 * 
 */
package me.myachievements.persistence.goal;

import java.util.Date;

import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;

import me.myachievements.persistence.PersistenceManagerImpl;

/**
 * @author besseym
 *
 */
public class GoalPersistenceManagerImpl extends PersistenceManagerImpl<Goal> implements GoalPersistenceManager {

	/**
	 * Constructor
	 */
	public GoalPersistenceManagerImpl(){
		super(Goal.class);
	}
	
	/*
	 * (non-Javadoc)
	 * @see me.myachievements.persistence.PersistenceManagerImpl#update(me.myachievements.persistence.PersistentObject)
	 */
	@Override
	public void update(Goal goal){
		goal.setUpdatedOn(new Date());
		super.update(goal);
	}
	
	/*
	 * (non-Javadoc)
	 * @see me.myachievements.persistence.goal.GoalPersistenceManager#get(java.lang.Long)
	 */
	public Goal get(Long id){
		return (Goal) this.getCurrentSession()
			.createCriteria(Goal.class)
			.setFetchMode("tags", FetchMode.JOIN)
			.add(Restrictions.idEq(id)).uniqueResult();
	}
	
	/*
	 * (non-Javadoc)
	 * @see me.myachievements.persistence.goal.GoalPersistenceManager#get(java.lang.String)
	 */
	public Goal get(String title){
		
		return (Goal) this.getCurrentSession()
			.createCriteria(Goal.class)
			.setFetchMode("tags", FetchMode.JOIN)
			.add(Restrictions.eq("title", title)).uniqueResult();
	}
}
